package playerclient;

import java.rmi.RemoteException;

import common.Player;
import common.Tools;
import common.PlayerService;

public class PlayerClient {

	private PlayerService playerService;

	public PlayerClient(PlayerService playerService) {
		this.playerService = playerService;
	}

	public void createPlayer(String firstName, String lastName, int age,
			String userName, String password, String clientIpAddress) {
		try {
			Player player = new Player(firstName, lastName, age, userName,
					password, clientIpAddress);
			Tools.writeLog("client", "client", "create player:" + player, false);
			playerService.createPlayerAccount(firstName, lastName, age,
					userName, password, clientIpAddress);
		} catch (RemoteException re) {
			Tools.writeLog("client", "client", re.detail.getMessage(), false);
		}
	}

	public void signIn(String userName, String password, String clientIpAddress) {
		try {
			String content = "player signIn started:" + "userName:" + userName +";ipAddress:"+ clientIpAddress;
			System.out.println(content);
			Tools.writeLog("client", "client", content, false);
			playerService.playerSignIn(userName, password, clientIpAddress);
			content = "player signIn succeeded:" + "userName:" + userName +";ipAddress:"+ clientIpAddress;
			System.out.println(content);
			Tools.writeLog("client", "client", content, false);
		} catch (RemoteException re) {
			Tools.writeLog("client", "client", re.detail.getMessage(), false);
		}
	}

	public void signOut(String userName, String clientIpAddress) {
		try {
			String content = "player signOut started:" + "userName:" + userName +";ipAddress:"+ clientIpAddress;
			System.out.println(content);
			Tools.writeLog("client", "client", content, false);
			playerService.playerSignOut(userName, clientIpAddress);
			content = "player signOut succeeded:" + "userName:" + userName +";ipAddress:"+ clientIpAddress;
			System.out.println(content);
			Tools.writeLog("client", "client", content, false);
		} catch (RemoteException re) {
			Tools.writeLog("client", "client", re.detail.getMessage(), false);
		}
	}

}